<?php
/**
 * Created by PhpStorm.
 * User: matengfei
 * Date: 15/8/23
 * Time: 下午5:42
 */

require_once 'snoopy.php';

class Search
{

    function __construct()
    {

    }

    ///*
    public function search($word)
    {
        $snoopy = new Snoopy();

        $result = $snoopy->fetchtext("http://nssug.baidu.com/su?prod=recon_dict&wd=" . $word);
        if ($result) {
            $content = $snoopy->results;
            $pos = stripos($content, "[") + 1;
            $pos_end = stripos($content, "]");
            $length = $pos_end - $pos;

            $substring = substr($content, $pos, $length);
            //$substring = explode(",", $substring);
            //$substring = json_encode($substring);

            echo $substring;
        } else {
            echo 'search error';
        }

    }
    //*/
}


$word = $_GET['word'];
$search = new Search();
$search->search($word);